﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESB.BAM.DAL;
using System.Data.Linq;

namespace ESB.BAM.BLogic
{
    /// <summary>
    /// This is a class to wrap the row of mapping data.
    /// </summary>
    public class ESBTrackingDataStep
    {
        public string DataName { get; set; }
        public string DataExtractionXPath { get; set; }

        /// <summary>
        /// Gets the data list.
        /// </summary>
        /// <param name="DALDataSet">The DAL data set.</param>
        /// <returns></returns>
        public static List<ESBTrackingDataStep> GetDataList(EntitySet<ESBTrackingData> DALDataSet)
        {
            if (DALDataSet == null) return null;
            var callToken = Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.TrackingComponent.TraceIn();
            List<ESBTrackingDataStep> Datalst = new List<ESBTrackingDataStep>();
            ESBTrackingDataStep dstep;
            foreach (ESBTrackingData datarow in DALDataSet)
            {
                dstep = new ESBTrackingDataStep()
                {
                    DataName = datarow.DataName,
                    DataExtractionXPath = datarow.DataExtractionXPath
                };
                Datalst.Add(dstep);
            }
            Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.TrackingComponent.TraceOut(callToken);
            return Datalst;
        }
        /// <summary>
        /// Gets the data at step.
        /// </summary>
        /// <param name="ServiceMilestoneId">The service milestone id.</param>
        /// <returns></returns>
        public static List<ESBTrackingDataStep> GetDataAtStep(long ServiceMilestoneId)
        {
            var callToken = Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.TrackingComponent.TraceIn();
            EsbTrackingProfilesDbCache cache = EsbTrackingProfilesDbCache.GetCache();
            List<ESBTrackingData> DALDataSet = cache.GetData(ServiceMilestoneId);
            List<ESBTrackingDataStep> Datalst = new List<ESBTrackingDataStep>();
            ESBTrackingDataStep dstep;
            foreach (ESBTrackingData datarow in DALDataSet)
            {
                dstep = new ESBTrackingDataStep()
                {
                    DataName = datarow.DataName,
                    DataExtractionXPath = datarow.DataExtractionXPath
                };
                Datalst.Add(dstep);
            }
            Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.TrackingComponent.TraceOut(callToken);
            return Datalst;
        }
    }
}
